<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:f="http://java.sun.com/jsf/core"
	  xmlns:h="http://java.sun.com/jsf/html">
	<f:view contentType="text/html"/>
	<h:body>
		<h:messages style="color: red"/>
		<h2>Cadastro de Lançamentos</h2>
		<h:form id="dados">
			<fieldset>
				<legend>Dados do Lançamento</legend>
			
			<h:panelGrid columns="2">
				<h:outputLabel value="Id:" for="id" 
						     rendered="#{lancamentoBean.lancamento.id != null}"
						     />
				<h:inputText id="id" 
							 value="#{lancamentoBean.lancamento.id}"
							 rendered="#{lancamentoBean.lancamento.id != null}"
							 readonly="true"/>

				<h:outputLabel value="Tipo (*):" for="descricao"/>
					<h:selectOneMenu value="#{lancamentoBean.lancamento.tipo}">  
			            <f:selectItem itemLabel="Entrada" itemValue="Entrada" />  
			            <f:selectItem itemLabel="Saída" itemValue="Saída" />  
		        	</h:selectOneMenu>

		        <h:outputLabel value="Descrição" for="descricao"/>
				<h:inputText id="descricao" 
							 value="#{lancamentoBean.lancamento.descricao}"/>

				<h:outputLabel value="Valor:" for="valor"/>
				<h:inputText id="valor" value="#{lancamentoBean.lancamento.valor}"/><br/>
				<h:commandButton value="Salvar" action="#{lancamentoBean.salvar}"/>
			</h:panelGrid>
			</fieldset>
		</h:form>
		
		<h2>Itens de Lançamentos</h2>
		<h:form id="tabela">
			<h:dataTable value="#{lancamentoBean.lancamentos}" var="lanc"
				styleClass="dados" rowClasses="impar,par" >
				<h:column>
					<f:facet name="header">
						<h:outputText value="Tipo" />
					</f:facet>
					#{lanc.tipo}
				</h:column>

				<h:column>
					<f:facet name="header">
						<h:outputText value="Descrição" />
					</f:facet>
					#{lanc.descricao}
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Valor" />
					</f:facet>
					#{lanc.valor}
				</h:column>			
				<h:column>
					<f:facet name="header">
						<h:outputText value="Ações" />
					</f:facet>
					<h:commandLink action="#{lancamentoBean.remover}" 
								   value="Remover">
						<f:ajax render="@form" />
						<f:setPropertyActionListener 
							target="#{lancamentoBean.lancamento}" 
							value="#{lanc}"/>
					</h:commandLink>
				</h:column>
				<h:column>
					<h:commandLink value="Alterar">
						<f:setPropertyActionListener 
							target="#{lancamentoBean.lancamento}" 
							value="#{lanc}"/>
					</h:commandLink>
				</h:column>
			</h:dataTable>
		</h:form>
	</h:body>
</html>